﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Entity;
using System.Collections.Generic;
using System.Web.Services;
using Meqs.Utilities;
using Meqs.Logic.Interface;

public partial class TeacherEval_School_Reprots_PoliticalEval : System.Web.UI.Page
{
    protected string KeyWord
    {
        get
        {
            return TeacherEvalHistory.PoliticsWorker_Term_Eval;
        }
    }
    protected int PoliticalID
    {
        get
        {
            return 4;
        }
    }
    protected IList<UserProjectScore> ups = null;
    protected IList<TeacherEvalType> evaltype = null;
    protected int index = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnBind_Click(object sender, EventArgs e)
    {
        SchoolInfo si = SchoolCommon.Sch_SchoolInfo;
        Hashtable ht = new Hashtable();
        ht.Add("SchoolMark", Common.GetConstSchoolMark());
        ht.Add("KeyWord", KeyWord);
        ht.Add("SchoolYear", Convert.ToInt32(Request.Form[schoolYear.UniqueID].ToString()));
        ht.Add("Term", Convert.ToInt32(Request.Form[schoolTerm.UniqueID].ToString()));
        ups = Container<ITeacherEvalCatchLogic>.Instance.FindKeyWordUserScore(ht);
        evaltype = Container<ITeacherEvalCatchLogic>.Instance.FindKeyWordTypeInfo(ht);

        ht = new Hashtable();
        ht.Add("RoleID", PoliticalID);
        ht.Add("SchoolYear", si.SchoolYear);
        ht.Add("Term", si.SchoolTerm);
        Repeater1.DataSource = Container<ITeacherEvalDesLogic>.Instance.FindOtherTeacher(ht);
        Repeater1.DataBind();

    }

    protected string GetHeader()
    {
        string str = "<tr>";
        str += "<th>姓名（工号）<span  id='img0'></span></th>";
        index = 1;
        foreach (TeacherEvalType type in evaltype)
        {
            str += "<th onclick='sort(" + index + ")'>" + type.Caption + "(总分)<span  id='img" + index + "'></span></th>";
            index++;
        }
        str += "<th onclick='sort(" + index + ")'>总评分<span id='img" + index + "'><img src='../../Common/images/1.gif' /></span></th></tr>";

        return str;
    }
    protected string GetTeacher(int id, string name, string coder)
    {
        string str = "<tr onclick='SetHightLight(this);'>";
        str += "<td>" + name + "（" + coder + "）</td>";
        float totle = 0;

        foreach (TeacherEvalType type in evaltype)
        {
            object s = GetTypeScore(id, type.RID);
            totle += (s == null) ? (float)0 : (float)(Math.Round(Convert.ToSingle(s), 1));
            string scorestr = (s == null) ? "" : Math.Round(Convert.ToSingle(s), 1).ToString();
            str += "<td >" + scorestr + "</td>";
        }
        str += "<td >" + totle + "</td></tr>";
        return str;
    }

    protected object GetTypeScore(int id, int typeid)
    {
        foreach (UserProjectScore u in ups)
        {
            if (u.UserID == id && u.ProjectID == typeid)
            {
                return u.Score;
            }
        }
        return null;
    }

    [WebMethod]
    public static string GetExcel(ExcelTableCell[][] cells)
    {
        string temp_path = HttpContext.Current.Server.MapPath("../../../");
        string save_path = temp_path + "\\download\\" + "行政人员评价.xls";
        HttpContext.Current.Session["filepath"] = save_path;
        Meqs.Utilities.ExcelUtil.ExcelExport(save_path, "行政人员评价", 1, 0, cells);
        return "";
    }
}
